{% extends 'base.html' %}
{% load myinclusion %}
{% block content %}
<div class="right_col" role="main">
    <div class="">
        <div class="clearfix"></div>

        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>任务查询<small>|&nbsp;<a href="{% url 'task_list' %}">任务列表</a></small></h2>
                        <ul class="nav navbar-right panel_toolbox">
                            <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                            </li>
                            <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                            <ul class="dropdown-menu" role="menu">
                                <li><a href="#">Settings 1</a>
                                </li>
                                <li><a href="#">Settings 2</a>
                                </li>
                            </ul>
                            </li>
                            <li><a class="close-link"><i class="fa fa-close"></i></a>
                            </li>
                        </ul>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <div class="loading"></div>
                        <form class="form-horizontal form-border" method="post" action="" enctype="multipart/form-data">
                            {% csrf_token %}

                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12">任务JID</label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <input class="form-control" id="id_name" maxlength="50" name="jid" type="text" required="">
                                </div>
                            </div>
                            <div class="item form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12">任务类型</label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <select name="check_type" class="form-control" data-bv-field="check_type">
                                        <option name="" value="">请选择</option>
                                        <option name="check" value="exec">远程管理</option>
                                        <option name="check" value="deploy">模块部署</option>
                                    </select>
                                </div>
                            </div>
                            <div name="ajax_result" class="item form-group"></div>
                            <div class="ln_solid"></div>
                            <div class="form-group">
                                <div class="col-md-6 col-md-offset-3">
                                    <button id="send" type="submit" class="btn btn-success">查询</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block js %}
<script src="/static/js/bootstrapValidator.min.js"></script>
<script src="/static/js/csrf.js"></script>
<script>
    $(document).ready(function(){
            $("form").bootstrapValidator({
fields:{
jid:{
validators:{
notEmpty:{
message:'请填写任务JID'
},
/*stringLength:{
min:20,
max:20,
message:'JID输入错误'
},*/
regexp:{
regexp:/^[0-9]+$/,
message:'输入错误'
}
}
},
check_type:{
validators:{
notEmpty:{
message:'请选择任务类型'
         }
           }
           }
}
})
         .on('success.form.bv',function(e){
            e.preventDefault();
            var check_type = $("select[name='check_type']").val();
            var jid = $("input[name='jid'").val();
            $(".loading").show();
            $.ajax({
type:"POST",
url:"{% url 'task_check' %}",
data:{jid:jid, check_type:check_type},
dataType:"html",
success:function(ret) {
$(".loading").hide();
var ret = eval('('+ret+')');
var html = "<label class=\"control-label col-md-3 col-sm-3 col-xs-12\">返回结果</label><div class=\"col-md-6 col-sm-6 col-xs-12\"><fieldset><textarea class=\"form-control\" rows=\"10\">"+ret+"</textarea></fieldset></div>";
$("div[name='ajax_result']").html(html);
},
});
            })
})
</script>
{% endblock %}
